<%-- 
    Document   : FolderPage
    Created on : 30.04.2011, 23:49:49
    Author     : ain
--%>

<%@page import="unc.pds.filemodel.FolderRemote"%>
<%@page import="unc.pds.model.DiaryRemote"%>
<%@page import="unc.pds.model.UserRemote"%>
<%@page import="unc.pds.data.Consts"%>
<%@page import="unc.pds.util.ArchImpl"%>
<%@page import="unc.pds.util.Arch"%>
<%@page import="unc.pds.service.*"%>
<%@page import="javax.naming.InitialContext"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Folder View</title>
    </head>
    <body>
        <%
                    ServiceBeanRemote sbr = (ServiceBeanRemote) session.getAttribute("service");
                    Long key;
                    FolderRemote fr;
                    key = new Long(Long.parseLong(request.getParameter("id")));
                    fr = (FolderRemote) sbr.getByKey(key);
                    FolderRemote[] folders = fr.getFolders();
                    for (int i = 0; i < folders.length; i++) {
                        out.println(
                                "<a href=FolderPage.jsp?id=" + folders[i].getKey() + ">" + folders[i].getName() + "</a><br>");
                    }
        %>
        <form action="FolderPage.jsp">
            <input type="text" name="name" value="New Folder">
            <input type="submit" name="newpost" value="newpost">
            <input type="text" readonly="true" name="id" value ="<%
                        out.print(fr.getKey());
                   %>">
        </form>
        <%
                    if (request.getParameter("newpost") != null) {
                        Arch doc = new ArchImpl("root", null);
                        doc.addChild(new ArchImpl(Consts.ATTR__FOLDER_NAME, request.getParameter("name")));
                        fr.addFolder(doc);
                        response.sendRedirect("FolderPage.jsp?id=" + fr.getKey());
                    }
        %>
    </body>
</html>
